package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.Participation;
import cn.edu.lingnan.service.IParticipationService;
import cn.edu.lingnan.service.IStudentService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@WebServlet("/queryPart")
public class queryStuPart extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String partName = req.getParameter("partName");
        HttpSession session = req.getSession();
        int sid = (int)session.getAttribute("sid");

        IParticipationService service = new IParticipationService();
        List<Participation> list = service.findParticipationBySid(sid);
        List<Participation> list2 = service.findParticipationByName(partName);

        if(partName==null||partName.equals("")){
            session.setAttribute("stuPart",list);//默认查询所有比赛记录
        }else{
            session.setAttribute("stuPart",list2);//模糊查询单个比赛记录
        }

        resp.sendRedirect(req.getContextPath()+"/user/findParticipation.jsp");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
